import { Keys } from '@/constants'
import { localStg } from '@/utils'

/** 获取token */
export function getToken() {
    return localStg.get(Keys.TOKEN) || ''
}

/** 获取用户信息 */
export function getUserInfo() {
    const emptyInfo: Auth.UserInfo = {
        id: '',
        username: '',
        avatar: '',
        isSystemAdmin: false
    }
    const userInfo: Auth.UserInfo = localStg.get(Keys.USER) || emptyInfo

    return userInfo
}

/** 去除用户相关缓存 */
export function clearAuthStorage() {
    localStg.remove(Keys.TOKEN)
    localStg.remove(Keys.REFRESH_TOKEN)
    localStg.remove(Keys.USER)
    localStg.remove(Keys.WEBSOCKET_TOKEN)
}
